﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Noria.Web.Utility;

namespace AJArt.Mvc.Models
{

    #region Models

    public class RazorModel
    {
    }

    #endregion

    #region Services

    public interface IRazorService
    {
        bool GenerateSite();
    }

    public class RazorService : IRazorService
    {
        public bool GenerateSite()
        {
            const string page = "index.htm";
            DirectoryInfo root = new DirectoryInfo(@"K:\web\anjie");
            var photos = HttpContext.Current.Server.MapPath("~/content/photos");

            //if (root.Exists)
            //    root.Delete(true);
            //root.Create();
            if (!root.Exists)
                root.Create();

            //copy content

            //首页
            RazorUtility.ApplyTemplateAndSave("", null, root.FullName + "/" + page, true);

            //关于
            RazorUtility.ApplyTemplateAndSave("Home/About", null, root.FullName + "/about/" + page, true);

            //Category
            foreach (var item in Directory.GetDirectories(photos))
            {
                DirectoryInfo cat = new DirectoryInfo(item);
                RazorUtility.ApplyTemplateAndSave("category/" + cat.Name, null, root.FullName + "/category/" + cat.Name + "/" + page, true);

                foreach (var s in cat.GetDirectories())
                {
                    RazorUtility.ApplyTemplateAndSave("category/" + cat.Name + "/" + s.Name, null, root.FullName + "/category/" + cat.Name + "/" + s.Name + "/" + page, true);
                }
            }

            return true;
        }
    }

    #endregion

    #region Validation
    #endregion

}
